﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Devtm.ServiceModel.Proxy;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

namespace Devtm.ServiceModel.Resolver.Connectors
{
    internal class EndpointAddressConnector : IServiceConnector
    {


        public EndpointAddressConnector(IServiceResolver resolver, EndpointAddress remoteAddress, Binding binding, params IEndpointBehavior[] behaviors)
        {
            Resolver = resolver;
            RemoteAddress = remoteAddress;
            Binding = binding;
            Behaviors = behaviors;
        }

        
        public object[] Parameters() 
        {
            UsedCount++;
            return new object[] { Binding, RemoteAddress, Behaviors }; 
        }


        public IServiceResolver Resolver { get; private set; }
        public EndpointAddress RemoteAddress { get; set; }
        public Binding Binding { get; set; }
        public IEndpointBehavior[] Behaviors { get; set; }
        public int UsedCount { get; private set; }

        public override int GetHashCode()
        {
            string k = RemoteAddress.Uri.AbsoluteUri + Resolver.Configuration.Interface.Name + Binding.GetType().Name;
            return k.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return obj.GetHashCode() == GetHashCode();
        }




        public Uri Uri
        {
            get { return RemoteAddress.Uri; }
        }
    }
}
